using System.Collections.Generic;
using System.Runtime.Serialization;

namespace GraphMyCode.Web.Dtos
{
	[DataContract]
	public class GraphDto
	{
		[DataMember]
		private readonly List<VertexDto> vertices = new List<VertexDto>();

		[DataMember]
		private readonly List<EdgeDto> edges = new List<EdgeDto>();

		public IEnumerable<VertexDto> Vertices
		{
			get { return vertices; }
		}

		public IEnumerable<EdgeDto> Edges
		{
			get { return edges; }
		}

		public void AddEdge(EdgeDto edge)
		{
			if (!edges.Contains(edge))
				edges.Add(edge);

			if (!vertices.Contains(edge.Source))
				vertices.Add(edge.Source);

			if (!vertices.Contains(edge.Target))
				vertices.Add(edge.Target);
		}

		public void AddVertex(VertexDto vertex)
		{
			if (!vertices.Contains(vertex))
				vertices.Add(vertex);
		}
	}
}